package com.etl.webservicenet.util;

import java.util.Arrays;
import java.util.Random;

/**
 * Created by DWQ on 2019/2/18.
 * E-Mail:lomapa@163.com
 */

public class HeaderSignEncryptUtils {


    /**
     * @param timestamp 时间戳
     * @param randomStr 随机串
     * @return
     */
    public static String getSignature(String timestamp, String randomStr) {
        String token = "YsAqJy8B3483D91DF881757DA76A364D3B31C5";//客户端 和服务器 共有taken 8B3483D91DF881757DA76A364D3B31C5
        String str = token + timestamp + randomStr;
        char[] strChars = str.toCharArray();
        Arrays.sort(strChars);
        StringBuilder stringBuilder = new StringBuilder();
        for (char c : strChars) {
            stringBuilder.append(c);
        }
        return MD5Util.getMd5(stringBuilder.toString());
    }

    //生成长度为6的字符串
    public static String getRandomString6() {
        String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < 6; i++) {
            int number = random.nextInt(62);
            sb.append(str.charAt(number));
        }
        return sb.toString();
    }
}
